<div class="layuimini-main">
    <div class="layui-form layuimini-form" style="width: 80%;margin-top: 20px;" lay-filter="addRoomForm">
        <div class="layui-form-item">
            <label class="layui-form-label layui-hide"></label>
            <div class="layui-input-block">
                <!-- 获取list页面传过来的楼栋ID与楼层数 -->
                <input type="hidden" id="buildingId" name="buildingId">
                <input type="hidden" id="floor" name="floor">

                <input type="hidden" id="id" name="id" lay-reqtext="宿舍编号不能为空"
                       placeholder="请输入宿舍编号" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label required">门牌号</label>
            <div class="layui-input-block">
                <input type="text" id="brand" name="brand" lay-verify="required" lay-reqtext="门牌号不能为空"
                       placeholder="请输入门牌号" value="" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">房间容量</label>
            <div class="layui-input-block">
                <select name="roomCapacity" lay-verify="required">
                    <option value="0">不住人</option>
                    <option value="1">1人间</option>
                    <option value="2">2人间</option>
                    <option value="4">4人间</option>
                    <option value="6">6人间</option>
                </select>
            </div>
        </div>

<!--        <div class="layui-form-item">-->
<!--            <label class="layui-form-label">房间状态</label>-->
<!--            <div class="layui-input-block">-->
<!--                <select name="roomStatus" lay-verify="required">-->
<!--                    <option value="0">空房间</option>-->
<!--                    <option value="1">未满</option>-->
<!--                    <option value="2">已满</option>-->
<!--                </select>-->
<!--            </div>-->
<!--        </div>-->

        <div class="layui-form-item">
            <label class="layui-form-label">房间类型</label>
            <div class="layui-input-block">
                <select name="roomType" lay-verify="required">
                    <option value="0">学生房间</option>
                    <option value="1">宿管房间</option>
                    <option value="2">后勤办公室</option>
                    <option value="3">招待所</option>
                    <option value="4">小卖部</option>
                    <option value="5">杂物间</option>
                </select>
            </div>
        </div>


        <div class="layui-form-item" style="text-align: center;margin-top: 30px;">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
            </div>
        </div>
    </div>
</div>


<script>
    layui.use(['form', 'table', 'axios'], function () {
        let form = layui.form,
            layer = layui.layer,
            axios = layui.axios,
            $ = layui.$;

        // 初始化表单
        form.render();

        // 当前弹出层，防止ID被覆盖
        let parentIndex = layer.index;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            axios.post('room/create', data.field).then(function (response) {
                if(response.code === 200){
                    layer.msg(response.msg);                        // layer的成功提示
                }
                layer.close(parentIndex);                           // 关闭弹出层
            }).catch(function (error) {
                layer.msg(error);
            });
            return false;
        });

    });
</script>